﻿
Imports System.ServiceModel
Imports System.Messaging
Imports ATS.WCFServices

Public Class HostClass
    Public Shared Sub Main() '(ByVal args As String())
        
        Dim _svcHost As ServiceHost = Nothing
        Try
            System.Console.WriteLine("Starting ATS Host ...")

            _svcHost = LoadATSService()

            DisplayWorkflowType()

            System.Console.WriteLine(vbLf & "ATS Console Host started. Press any key to exit." & vbLf & vbLf)
            System.Console.Read()
        Catch
            System.Console.WriteLine(vbLf & "Host initialization has failed.")
            System.Console.WriteLine("Press any key to terminate.")
            System.Console.Read()
        Finally
            If _svcHost IsNot Nothing Then
                _svcHost.Close()
            End If
        End Try

    End Sub

    Private Shared Function LoadATSService() As ServiceHost
        Dim svcHost As ServiceHost = Nothing
        Try
            System.Console.Write("Loading ATS Service ... ")

            ' Create Service Host.
            svcHost = New ServiceHost(GetType(WCFServices.AssetService))
            svcHost.Open()

            System.Console.WriteLine("Done!")
        Catch ex As Exception
            System.Console.WriteLine(vbLf & "Error Loading ATS Service. ")
            System.Console.WriteLine("Exception : " & ex.Message)
            Throw ex
        End Try

        Return svcHost
    End Function


    Private Shared Sub DisplayWorkflowType()
        'Console.Write("Workflow Type: ");
        'if (ConfigurationManager.AppSettings["WorkflowType"].ToString() == "StateMachine")
        '    Console.WriteLine("StateMachine");
        'else
        '    Console.WriteLine("Sequential");
    End Sub

End Class
